﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Service;
namespace community
{

    public partial class familycheck : Form
    {
        string ck;
        DataTable table;
        public static string ck_JTBH="";//家庭编号
        public familycheck()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            if (textBox1.Text == "")
            {
                MessageBox.Show("请输入检索内容", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            ck = Convert.ToString(textBox1.Text);
            if (radioButton1.Checked)
            {
                str = "select b.FAMILYCORD_CHR as 家庭编号,a.RESIDENTNAME_CHR as 户主姓名,a.INHABITANTCODE_CHR as 户主编号,c.COMMUNITYNAME_VCHR as 社区,b.MEMBERCOUNT_INT as 家庭人口,b.HOMEADDRESS_VCHR as 家庭地址 from T_CS_COMMUNITY as c,T_CS_FAMILYRECORD as b,T_CS_INHABITANTRECORD_NEW as a  where b.COMMUNITYCODE_CHR=c.COMMUNITYCODE_CHR and a.INHABITANTCODE_CHR=b.INHABITANTCODE_CHR and a.RESIDENTNAME_CHR='" + ck + "'";
            }
            else if (radioButton2.Checked)
            {
                str = "select b.FAMILYCORD_CHR as 家庭编号,a.RESIDENTNAME_CHR as 户主姓名,a.INHABITANTCODE_CHR as 户主编号,c.COMMUNITYNAME_VCHR as 社区,b.MEMBERCOUNT_INT as 家庭人口,b.HOMEADDRESS_VCHR as 家庭地址 from T_CS_COMMUNITY as c,T_CS_FAMILYRECORD as b,T_CS_INHABITANTRECORD_NEW as a  where b.COMMUNITYCODE_CHR=c.COMMUNITYCODE_CHR and a.INHABITANTCODE_CHR=b.INHABITANTCODE_CHR and a.INHABITANTCODE_CHR='" + ck + "'";
            }
            else if (radioButton3.Checked)
            {
                str = "select b.FAMILYCORD_CHR as 家庭编号,a.RESIDENTNAME_CHR as 户主姓名,a.INHABITANTCODE_CHR as 户主编号,c.COMMUNITYNAME_VCHR as 社区,b.MEMBERCOUNT_INT as 家庭人口,b.HOMEADDRESS_VCHR as 家庭地址 from T_CS_COMMUNITY as c,T_CS_FAMILYRECORD as b,T_CS_INHABITANTRECORD_NEW as a  where b.COMMUNITYCODE_CHR=c.COMMUNITYCODE_CHR and a.INHABITANTCODE_CHR=b.INHABITANTCODE_CHR and b.FAMILYCORD_CHR='" + ck + "'";
            }
            SqlConnection cn = new SqlConnection(SQL.conStr);
            SqlDataAdapter dt = new SqlDataAdapter(str, cn);
            DataSet ds = new DataSet();
            cn.Open();
            dt.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
            cn.Close();
            //Cls_DBHelper help = new Cls_DBHelper();

            //table = help.m_clsGetDataSet(str);
            //dataGridView1.DataSource = table;

            //if(radioButton2.Checked)
            //    str 

            //    if (radioButton1.Checked) str1 = " residentname_chr='";
            //    if (radioButton2.Checked) str1 = " identitycard_chr='";
            //    if (radioButton3.Checked) str1 = " inhabitantcode_chr='";
            //    if (radioButton5.Checked) str1 = "communityname_chr='";
            //    str = "select inhabitantcode_chr as 居民编号,residentname_chr as 居民姓名,identitycard_chr as 身份证号,sex_chr as 性别,birth_dat as 出生日期, communityname_chr as 所属社区,communitycode_chr as 社区编号,familycode_chr as 家庭编号  from  t_cs_inhabitantrecord_new where" + str1 + ck + "'";
            //    SqlConnection cn = new SqlConnection(SQL.conStr);
            //    cn.Open();
            //    SqlDataAdapter dt = new SqlDataAdapter(str, cn);
            //    DataSet ds = new DataSet();
            //    dt.Fill(ds);
            //    dataGridView1.DataSource = ds.Tables[0];
            //    cn.Close();
        }

        private void familycheck_Load(object sender, EventArgs e)
        {
            textBox1.Text = "";
            string str = "select b.FAMILYCORD_CHR as 家庭编号,a.RESIDENTNAME_CHR as 户主姓名,a.INHABITANTCODE_CHR as 户主编号,c.COMMUNITYNAME_VCHR as 社区,b.MEMBERCOUNT_INT as 家庭人口,b.HOMEADDRESS_VCHR as 家庭地址 from T_CS_COMMUNITY as c,T_CS_FAMILYRECORD as b,T_CS_INHABITANTRECORD_NEW as a  where b.COMMUNITYCODE_CHR=c.COMMUNITYCODE_CHR and a.INHABITANTCODE_CHR=b.INHABITANTCODE_CHR and  b.FAMILYCORD_CHR!=''";
            //Cls_DBHelper help = new Cls_DBHelper();
            //table = help.m_clsGetDataSet(str);
            //dataGridView1.DataSource = table;
            SqlConnection cn = new SqlConnection(SQL.conStr);
            SqlDataAdapter dt = new SqlDataAdapter(str, cn);
            DataSet ds = new DataSet();
            cn.Open();
            dt.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
            cn.Close();
            
        }

        private void dataGridView1_RowHeaderCellChanged(object sender, DataGridViewRowEventArgs e)
        {

        }

        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            ck_JTBH=dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
            this.Visible=false;
            
        }
    }
}
